package Offer2018;

/**
 * Created by 雷文康 on 2018/3/3.
 */
public class Test12a {

    public static void main(String[] args) {
        printToN(3);
    }

    public static void printToN(int n) {
        if (n <= 0) {
            return;
        }
        int[] array = new int[n];
        printToN(array, 0);
    }

    public static void printToN(int[] array, int start) {
        if (start == array.length) {
            print(array);
            return;
        }
        for (int i = 0; i < 10; i++) {
            array[start] = i;
            printToN(array, start + 1);
        }
    }

    private static void print(int[] array) {
        boolean flag = false;
        for (int i = 0; i < array.length; i++) {
            if (array[i] != 0) {
                flag = true;
            }
            if (flag) {
                System.out.print(array[i]);
            }
        }
        System.out.print(" ");
    }
}
